package day16.edu;
// Created: 16/09/2025, ChangJiang Ru

import java.util.Scanner;

public class UserTest {
    public static void main(String[] args) {
        User[] arr = new User[3];
        arr[0] = new User("songhk", "123");
        arr[1] = new User("Tom", "8888");
        arr[2] = new User("Jerry", "6666");

        System.out.println("We have the Users: ");
        for (int i = 0; i < arr.length; i++)
        {
            System.out.println(arr[i]);
        }

        Scanner scan = new Scanner(System.in);
        System.out.print("Please input you name: ");
        String userName = scan.next();
        System.out.print("Please input you password: ");
        String userPassword = scan.next();

        /*
        for (int i = 0; i < arr.length; i++) {
            if(arr[i].getName().equals(userName) && arr[i].getPassword().equals(userPassword))
            {
                System.out.println("Input successfully!" + userName);
                break;
            }else if (arr[i].getName().equals(userName))
            {
                System.out.println("Password Error!");
                break;
            }else
            {
                System.out.println("No this User!");
                break;
            }
        }

         */

        boolean isFlag = true;
        for(int i = 0; i < arr.length; i++)
        {
            if(arr[i].getName().equals(userName))
            {
                isFlag = false;
                if(arr[i].getPassword().equals(userPassword))
                {
                    System.out.println("Input successfully, " + userName);
                }else
                    System.out.println("Password Error!");
                break;
            }
        }

        if(isFlag)
            System.out.println("No this User!");
        scan.close();
    }
}
